home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93a.txt / 000107_icon-group-sender _Thu Apr 1 17:27:10 1993.msg < prev    next >
Internet Message Format  |  1993-04-21  |  3KB

  1. Received: by cheltenham.cs.arizona.edu; Fri, 9 Apr 1993 16:52:55 MST
  2. Date: 1 Apr 93 17:27:10 GMT
  3. From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!msuinfo!uchinews!ellis!goer@ucbvax.Berkeley.EDU  (Richard L. Goerwitz)
  4. Organization: University of Chicago
  5. Subject: Re: help an Icon rookie
  6. Message-Id: <1993Apr1.172710.5099@midway.uchicago.edu>
  7. References: <9346@kielo.uta.fi>
  8. Sender: icon-group-request@cs.arizona.edu
  9. To: icon-group@cs.arizona.edu
  10. Status: R
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12.  
  13. In article <9346@kielo.uta.fi> jere@uta.fi (Jere K{pyaho) writes:
  14.  
  15. >Can I ask stupid questions in this newsgroup? Thanks.
  16.  
  17. A beginner's question yours was.  Not a *stupid* one.  Beginners'
  18. queries are the lifeblood of any newsgroup about any language that
  19. isn't overwhelmed with traffic.
  20.  
  21. >Now, I understand that this
  22. >
  23. >    procedure genchar( s, c )
  24. >        every i := ( s ? upto( c ) ) do
  25. >            write ( i )
  26. >    end
  27. >
  28. >outputs the positions of every character of 'c' in 's'.
  29. >But how do I output the corresponding _characters_ in 's'?
  30.  
  31. To do this, you have to subscript.  There are many ways to do it.
  32. You can also use the scanning mechanism itself.  One thing to nail
  33. down beforehand is how to group scanning expressions for clarity.
  34. Normally, it's best to make the scanning expression the outer con-
  35. trol structure.  This makes modification simpler.  In the above pro-
  36. cedure, though, there actually wasn't any reason to scan:
  37.  
  38.         procedure genchar(s,c)
  39.             local i
  40.             every i := upto(c, s) do
  41.                 write(i)
  42.         end
  43.  
  44. or better yet
  45.  
  46.         procedure genchar(s,c)
  47.             local i
  48.             every write(upto(c, s))
  49.         end
  50.  
  51. If you want to output the actual character matched, then you just add
  52. a subscripting mechanism:
  53.  
  54.         procedure genchar(s,c)
  55.             local i
  56.             every i := upto(c, s) do
  57.                 write(s[i])
  58.         end
  59.  
  60. or more compactly (but maybe less clearly):
  61.  
  62.         procedure genchar(s,c)
  63.             local i
  64.             every write( s[upto(c, s)] )
  65.         end
  66.  
  67. I probably would have solved the problem myself in an entirely different
  68. way, though, using scanning:
  69.  
  70.         procedure genchar(s, c)
  71.             s ? {
  72.                 while tab(upto(c)) do
  73.                   write(move(1))
  74.             }
  75.         end
  76.  
  77. Or more compactly:
  78.  
  79.         procedure genchar(s, c)
  80.             s ? while write( (tab(upto(c)), move(1)) )
  81.         end
  82.  
  83. Please don't hesitate to ask beginner questions here.  This newsgroup
  84. is not at all hostile to them.  Please check my code before using it,
  85. as I've had to write a lot of C lately, and I don't shift languages
  86. very well.
  87.  
  88. -- 
  89.  
  90.    -Richard L. Goerwitz              goer%midway@uchicago.bitnet
  91.    goer@midway.uchicago.edu          rutgers!oddjob!ellis!goer
  92.